// pages/set/serve/list/list.js
const app = getApp()
let drawQrcode = require("../../../../module/utils/ewm.js")
Page({

	/**
	 * 页面的初始数据
	 */
	data: {

	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		let that = this
		wx.getLocation({
			type: 'wgs84', // 默认wgs84
			success: function(res) {
				let x_pi = (3.14159265358979324 * 3000.0) / 180.0;
				let x = res.longitude - 0.0065;
				let y = res.latitude - 0.006;
				let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
				let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
				let lngs = z * Math.cos(theta);
				let lats = z * Math.sin(theta);
				wx.getStorage({
					key: 'uid',
					success: (en) => {
						wx.request({
							url: getApp().globalData.http + 'action=shopServerOrderDetail&oid=' + options.id + '&uid=' + en.data.uid +
								'&Longitude=' + lngs + '&Latitude=' + lats,
							success: (e) => {
								console.log(e)
								that.setData({
									uid:en.data,
									data: e.data.data
								})
								if(e.data.data.Status==1){
									that.ewmChange()
								}
							}
						})
					}
				})
			},
		});
	},
	mobile(e) {
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.num
		})
	},
	none(res) {
		wx.showModal({
			title: '您确定要取消订单吗？',
			success: (e) => {
				console.log(e)
				if (e.confirm) {
					wx.request({
						url: getApp().globalData.http + 'action=canelServerOrder&id=' + res.currentTarget.dataset.id + '&userID=' +
							this.data.uid.uid,
						success: (e) => {
							wx.navigateBack({
								delta: 1
							})
						}
					})
				}
			}
		})
	},
	dele(en) {
		wx.showModal({
			title: '您确定要删除订单吗？',
			success: (e) => {
				console.log(e)
				if (e.confirm) {
					wx.request({
						url: getApp().globalData.http + 'action=deleteServerOrder&oid=' + en.currentTarget.dataset.id + '&uid=' +
							this.data.uid.uid,
						success: (e) => {
							console.log(e)
							wx.navigateBack({
								delta: 1
							})
						}
					})
				}
			}
		})
	},
	ewmChange(){
	  let size = {}
	  size.w = wx.getSystemInfoSync().windowWidth / 750 * 400
	  size.h = size.w
	  var that = this
	
	  drawQrcode({
	    width: size.w,
	    height: size.h,
	    canvasId: 'myQrcode',
	    // ctx: wx.createCanvasContext('myQrcode'),
	    text: that.data.data.OrderCode+'&'+that.data.data.oid,
	    // v1.0.0+版本支持在二维码上绘制图片
	  })
	},
})
